package com.acwing.partition7;

import java.io.*;
import java.util.Arrays;

/**
 * @author rkc
 * @date 2022/8/2 9:39
 */
public class AC692G巴士计数 {

    private static final int N = 5010;
    private static int[] w = new int[N];
    private static int n;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int t = nextInt();
        for (int k = 1; k <= t; k++) {
            n = nextInt();
            Arrays.fill(w, 0);
            for (int i = 0; i < n; i++) {
                int l = nextInt(), r = nextInt();
                w[l]++;
                w[r + 1]--;
            }
            for (int i = 1; i < N; i++) w[i] += w[i - 1];
            writer.format("Case #%d: ", k);
            int q = nextInt();
            while (q-- > 0) {
                int x = nextInt();
                writer.print(w[x] + " ");
            }
            writer.println();
        }
        writer.flush();
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
